package client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.cps.platform.client.hbase.HbaseClient;
import com.cps.platform.core.hbase.HbasePut;

/**
 * <p>
 * 文件名称: HbaseClientMain.java
 * </p>
 * <p>
 * 文件描述: HBASE客户端测试MAIN方法
 * <p>
 * 版权所有: 版权所有(C)2011
 * </p>
 * <p>
 * 公 司: 联通系统集成有限公司
 * </p>
 * <p>
 * 完成日期：2012-12-6
 * </p>
 * 
 * @author ChenZhang
 */
public class HbaseClientMain {

	private static Logger log = Logger.getLogger(HbaseClientMain.class);
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String appId = "appId";
		String authToken = "authToken";
		String tenantId = "firelight";
		String tablename = "testClientTableName";
		
		HbaseClient hc = new HbaseClient();
		
		//表结构
		hc.createTable(appId, authToken, tenantId, tablename);
		//hc.dropTable(appId, authToken, tenantId, tablename);
		
		//添加
		HbasePut hbasePut = new HbasePut();
		hbasePut.setTableName(tablename);
		hbasePut.setRowKey("test_rowkey_20121206_001");
		Map<String, String> keyValues = new HashMap<String, String>();
		keyValues.put("name", "firelight");
		keyValues.put("age", "30");
		hbasePut.setKeyValues(keyValues);
		hbasePut = hc.saveData(appId, authToken, tenantId, hbasePut);
		log.info("[Main] op:saveData  rowkey:"+hbasePut.getRowKey());
		log.info("[Main] ----------------------");
		hbasePut.setRowKey("test_rowkey_20121206_002");
		keyValues = new HashMap<String, String>();
		keyValues.put("name", "CHEN");
		keyValues.put("age", "50");
		hbasePut.setKeyValues(keyValues);
		hbasePut = hc.saveData(appId, authToken, tenantId, hbasePut);
		log.info("[Main] op:saveData rowkey:"+hbasePut.getRowKey());
		log.info("[Main] ----------------------");
		
		//删除
		String rowKey = "test_rowkey_20121206_001";
		List<String> rowKeys = new ArrayList<String>();
		rowKeys.add(rowKey);
		hc.removeDatas(appId, authToken, tenantId, tablename, rowKeys);
		hc.removeData(appId, authToken, tenantId, tablename, rowKey);
		
		//查询
		/*hbasePut = hc.getData(appId, authToken, tenantId, tablename, rowKey);
		log.info("[Main] op:getData rowkey:"+hbasePut.getRowKey());
		log.info("[Main] ----------------------");
		List<HbasePut> puts = hc.queryAllData(appId, authToken, tenantId, tablename);
		log.info("size:"+puts.size());
		for(HbasePut put:puts) {
			log.info("[Main] op:queryAllData tableName:"+put.getTableName());
			log.info("[Main] op:queryAllData rowkey:"+put.getRowKey());
			log.info("[Main] ----------------------");
		}
		
		List<FilterBean> filterBeans = new ArrayList<FilterBean>();
		FilterBean filterBean1 = new FilterBean("age","30",FilterBean.FILTER_SIGN_COLUMN);
		filterBeans.add(filterBean1);
		puts = hc.queryMoreData(appId, authToken, tenantId, tablename, filterBeans);
		log.info("[Main] op:queryMoreData size:"+puts.size());
		for(HbasePut put:puts) {
			log.info("[Main] op:queryMoreData tableName:"+put.getTableName());
			log.info("[Main] op:queryMoreData rowkey:"+put.getRowKey());
			log.info("[Main] ----------------------");
		}*/
	}
}
